<!DOCTYPE html>
<html>
<head lang="en">
	<title>发表动态</title>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
	<script src="/js/jquery/jquery.min.js"></script>
	<script src="/js/bootstrap/js/bootstrap.min.js"></script>
	<link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
	<link rel="stylesheet" href="/css/reset.css"/>
	<link rel="stylesheet" href="/css/myStrategyComment.css"/>
	<script src="/js/plugins/jrender/jrender.min.js"></script>
	<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
	<script src="/js/plugins/dialog2/dialog.min.js"></script>
	<script src="/js/plugins/jquery-form/jquery.form.js"></script>
	<script src="/js/common.js"></script>
	<script>
        $(function () {
            var content="";
            var pointedFriends = sessionStorage.getItem("pointedFriends");
            var aitedFriends = sessionStorage.getItem("aitedFriends");
            if(pointedFriends){
                $.get("/users/more",{ids:pointedFriends},function (data) {
                    var html='';
                    $.each(data,function (index,ele) {
                        html+='<img src="'+ele.headImgUrl+'" width="20" style="margin-top: -68px;"/>';
                    })
                    $("#PointedheadImgUrls").html(html+"<span style='margin-left: -37px;border-bottom-width: 10px;border-top-width: 10px;'>可见</span>")
                })
			}
			if(aitedFriends){
                $.get("/users/more",{ids:aitedFriends},function (data) {
                    var html='';
                    $.each(data,function (index,ele) {
                        html+='<span>@'+ele.nickName+'</span>';
                    })
                    $("#AitedheadImgUrls").html(html)
                })
			}

			var status;
            if(sessionStorage.getItem("viewRange")){
                $("#view").html(sessionStorage.getItem("viewRange"));
            }
            $(".dropdown-menu a").click(function () {
				if($(this).html()=="所有好友可见"){
                    $("#view").html("所有好友可见");
                    sessionStorage.setItem("viewRange","所有好友可见")
                    status=0;
				}else if($(this).html()=="仅仅自己可见"){
                    $("#view").html("仅仅自己可见");
                    sessionStorage.setItem("viewRange","仅仅自己可见")
                    status=-1
				}else if($(this).html()=="指定谁可见"){
                    if($(".rect img")){
                        sessionStorage.setItem("sessionAllImgs",$("#allImgs").html());
                    }
                    content=$("textarea").val();
                    if(content){
                        sessionStorage.setItem("content",content);
                    }
                    sessionStorage.setItem("viewRange","指定谁可见")
                    status=1
				}
            })

			$(".aitedFriends").click(function () {
                if($(".rect img")){
                    sessionStorage.setItem("sessionAllImgs",$("#allImgs").html());
                }
                content=$("textarea").val();
                if(content){
                    sessionStorage.setItem("content",content);
				}
            })


			var clickImg;
            if(sessionStorage.getItem("sessionAllImgs")){
                $("#allImgs").html(sessionStorage.getItem("sessionAllImgs"))

            }

            if(sessionStorage.getItem("content")){
                $("textarea").val(sessionStorage.getItem("content"))
			}
            $(".rect").click(function () {
                clickImg=$(this)
				$("#fileForm input").click();
            })
			$("#fileForm input").change(function () {
                $("#fileForm").ajaxSubmit(function (data) {
                    var imgHtml="";
                    if(data.status==1){
                        imgHtml+='<img src="'+data.url+'">'
                        clickImg.html(imgHtml)
                    }
                })
            })




            //清空sessionStorage /mine/profiles.html
            $("#removeSessionStorage1").click(function () {
				sessionStorage.removeItem("viewRange");
				sessionStorage.removeItem("sessionAllImgs");
				sessionStorage.removeItem("pointedFriends");
				sessionStorage.removeItem("aitedFriends");
				sessionStorage.removeItem("content");
				location.href="/mine/profiles.html";
            })
			$("#removeSessionStorage2 button .btn1").click(function () {
                sessionStorage.removeItem("viewRange");
                sessionStorage.removeItem("sessionAllImgs");
                sessionStorage.removeItem("pointedFriends");
                sessionStorage.removeItem("aitedFriends");
                sessionStorage.removeItem("content");
                window.history.go(-1);
            })

			//提交表单
			$(".btn2").click(function () {
                //准备表单提交数据
                var pics="";
                $.each($(".rect img"),function (index,ele) {
                    if($(ele).attr("src")){
                        var pics2 = $(ele).attr("src");
                        pics2+=";";
                        pics+=pics2;
                    }
                })
                content=$("textarea").val();
                var submitData={pics:pics,content:content,
					aitedfriendIds:aitedFriends,pointedfriendIds:pointedFriends,
                    status:status,isRelease:true
                }
                $.post("/friendNews",submitData,function (data) {
                    location.href="/mine/dynamic.html"
                })
            })
        })
	</script>
</head>

<body>
<form id="fileForm" action="/images" method="post" enctype="multipart/form-data">
	<input type="file" name="pic" id="file" style="display: none">
</form>
<div class="search-head">
	<div class="row nav-search">
		<div class="col">
			<a href="/mine/profiles.html" id="removeSessionStorage1">
				<span><i class="fa fa-chevron-left" ></i></span>
			</a>
		</div>
		<div class="col">
			<span>发布朋友圈</span>
		</div>
		<div class="col"></div>
	</div>
</div>
<div class="comment">
	<div class="container imgs ">
		<span class="fa fa-camera" style="color: rgb(107, 198, 104); font-size: 22px;"></span>
		<div class="row" id="allImgs">
			<div class="col-3 rect">
				<span>上传</span>
			</div>
			<div class="col-3 rect">
				<span>上传</span>
			</div>
			<div class="col-3 rect">
				<span>上传</span>
			</div>
		</div>
	</div>
	<textarea name="content" class="form-control" rows="5" placeholder="这一刻的想法..."></textarea>
	<a class="btn btn-link aitedFriends" href="dynamicAit.html" role="button" style="border-left-width: 290px;margin-top: 0px;border-bottom-width: 0px;">@谁</a>
	<nav class="navbar navbar-default" role="navigation">
		<div>
			<ul class="nav navbar-nav">
				<li class="dropdown">
					<a href="#" class="dropdown-toggle" data-toggle="dropdown" id="viewRange">
						<span id="view" style="margin-left: 235px;">可见范围</span>
						<b class="caret"></b>
					</a>

					<ul class="dropdown-menu" style="margin-left: 234px;margin-right: 0px;">
						<li><a href="#">所有好友可见</a></li>
						<li><a href="#">仅仅自己可见</a></li>
						<li><a href="dynamicPoint.html">指定谁可见</a></li>
					</ul>
				</li>
			</ul>
		</div>
	</nav>

	</div>

	<div  id="PointedheadImgUrls">
	</div>
	<div  id="AitedheadImgUrls">

	</div>

</div>
<div class="operation" id="removeSessionStorage2">
	<button class="btn1" >放弃发布</button>
	<button class="btn2" id="submitBtn">发布动态</button>
</div>

</body>
</html>